﻿namespace Pyramid.Tests
{
    using System;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Pyramid.Hardware;
    using Pyramid.Hardware.Interop;

    [TestClass]
    public class MultilineDecoderTest
    {
        [TestMethod]
        public void ShouldDecodeInputValue()
        {
            var inputWidth = 5;

            var inputLines = new VariableInputBus(inputWidth);

            var target = new MultilineDecoder(inputLines.OutputBus);

            int range = (int)Math.Pow(3, inputWidth);
            int halfRange = (int)(range / 2);

            for (int input = -halfRange; input < (halfRange + 1); input++)
            {
                var expected = "0t" + new string('Z', halfRange - input) + '1' + new string('Z', halfRange + input);

                inputLines.SetValue((Tryte)input);

                for (int lineIndex = 0; lineIndex < range; lineIndex++)
                {
                    if (lineIndex == input + halfRange)
                    {
                        Assert.AreEqual(Trivalent.True, target.OutputBus.ElementAt(lineIndex).Signal);
                    }
                    else
                    {
                        Assert.AreEqual(Trivalent.False, target.OutputBus.ElementAt(lineIndex).Signal);
                    }
                }
            }
        }
    }
}
